<?php
if (!defined("BASEPATH")) exit("No direct script access allowed");

if(isset($_POST["input_workpage"]) AND isset($_POST["input_redirect"]) AND $_POST["input_workpage"] != "") {
	$strPost = "";

	foreach($_POST as $key => $val) {
		if(is_array($val)) {
			foreach($val as $key2 => $val2) {
				$strPost .= " + '&".$key."[]=' + encodeURIComponent(".$this->db->escape($val2).")";
			}
		}
		else {
			$strPost .= " + '&".$key."=' + encodeURIComponent(".$this->db->escape($val).")";
		}
	}
	if(strlen($strPost) > 0) {
		$strPost = "'".substr($strPost,5);
	}

	echo	"<script type=\"text/javascript\">
					$.ajax({
						type: 'POST',
						url: ".$this->db->escape($_POST["input_workpage"]).",
						data: ".$strPost.",
						error: function() {
							alert('Sorry!');
							//window.location = '';
						},
						success: function(response) {
							if(response.substr(0,9) == 'redirect=') {
								window.location = response.substr(9);
							} else if(response != '') {
								document.write(response);
								alert('.');
								window.location =".$this->db->escape($_POST["input_redirect"]).";
							} else {
								window.location =".$this->db->escape($_POST["input_redirect"]).";
							}
						}
					});
				</script>";

	echo	"<div style=\"text-align:center;\">";
	echo		"<table style=\"margin-left:auto; margin-right:auto;\">";
	echo			"<tr>";
	echo				"<td class=\"r vm\" style=\"border:0;\">";
	echo					"<img src=\"".MEDIA."img/page/working.gif\" alt=\"working\"/>";
	echo				"</td>";
	echo				"<td class=\"vm b\" style=\"border:0; padding: 4px;\">Please wait...</td>";
	echo			"</tr>";
	echo		"</table>";
	echo	"</div>";
} else {
	redirect("", "refresh");
}
?>